# Relevant Data and Code Information for "Misery Needs Company: Contextualizing the Geographic and Temporal Link between Unemployment and Suicide"

We offer here all R and Stata codes to reproduce all figures and tables in the paper, Lee, Byungkyu and Bernice Pescosolido, 2024, "Lee, Byungkyu, and Bernice Pescosolido. "Misery Needs Company: Contextualizing the Geographic and Temporal Link between Unemployment and Suicide," _American Sociological Review_, forthcoming

If you have any problems or issues replicating our figures/tables, please contact BK Lee (bklee@nyu.edu).

You can run `META_multilevel_suicide.R` to replicate and reproduce all tables and figures.

# some remarks on data sources

1. NVDRS data is restricted and requires application to the CDC and an approved project-specific Data Use Agreement. Since we are not allowed to post and share suicide case data from NVDRS, we instead provide R codes to clean and generate the procssed NVDRS data (`1_clean_NVDRS.R`). Note that this code may not work for later versions of NVDRS data. Please visit the following NVDRS website to get access to the data.
  * https://www.cdc.gov/nvdrs/about/nvdrs-data-access.html

2. The ACS PUMS data are available via IPUMS USA website (https://usa.ipums.org/usa/). We shared the compressed ACS PUMS data (`rawdata_sharable/microACS_ipums.fst`) that we downloaded from this IPUMS website.

3. To create matching weights that assign PUMAs to counties in the ACS PUMS data, we downloaded two county-puma link files from Geocorr 2014 (http://mcdc.missouri.edu/applications/geocorr2014.html) website. We downloaded commuting zone-puma link files from the David Dorn's website (https://www.ddorn.net/data.htm). We included all these files in the `rawdata_sharable` folder.

4. Other county-level data sets (i.e., population count, and land area size) can be obtained from the following US census website. We have included the processed files under `rawdata_sharable` folder.
  * landarea : https://www.census.gov/library/publications/2011/compendia/usa-counties-2011.html
  * population count : https://www2.census.gov/programs-surveys/popest/datasets/2010-2019/counties/totals/ and https://www2.census.gov/programs-surveys/popest/datasets/2000-2010/intercensal/county/co-est00int-tot.csv

5. State-UI benefits: Unemployment insurance data from U.S. Department of Labor https://oui.doleta.gov/unemploy/DataDashboard.asp We added this data to `rawdata_sharable` folder.

6. Monthly Unemployment	Rates: We downloaded monthly unemployment rate data from https://data.bls.gov/timeseries/LNS14000000 We added this data to `rawdata_sharable` folder.

# Workflow to replicate results in the paper

If you specify your home directory in `META_run.R` file, then you should be able to reproduce all figures and tables in the paper. Specifically, 

## data cleaning 
1. `1_clean_NVDRS.R` : clean NVDRS data
2. `1a_clean_nvdrs_occupation.R` : clean NVDRS occupation data to identify the employment status based on the usual and current occupation text fields. We manually reviewed this file, and included the cleaned version of data you need to identify the employment status under `processed_sharable/nvdrs_occupation_coding_coded_final.xlsx`.
3. `1d_clean_ACS_PUMS.R` : clean ACS PUMS data
4. `2a_create_ACS_county_weight.R`: using GeoCorr 2014 matching files, create county-weights and CZ-weights for living individuals in ACS PUMS data
  * weight for ACS control : `PerWgt` * `# in county or cz i among J / # in PUMA j`
  * weight for NVDRS cases : 1
5. `3a_aggregate_measures.R` : merge NVDRS and ACS data with other data for regression analysis.
6. `3b_clean_regdata.do` : further clean regression data using Stata.

## analysis: figures and tables
1. `1c_figure_s2_wordcloud_by_occupation.R` : Figure S2  in Appendix
2. `4a_figure_s1_compare_cmf_nvdrs.R`: Figure S1, Tables S2-3 in Appendix, 
3. `5a_descriptive_analysis.do` : Table A1, Figure 1.
4. `5a_Figure1_overtime_association.R`: Figure 1.
5. `5a_figure_s3_bivariate_association.R` : Figure S3 in Appendix
6. `5b_sameness_main.do` + `5b_figure2_figures4_sameness_main.R` : Figure 2 and Figure S4 in Appendix
7. `5c_sameness_main_overtime.do` + `5c_figures6_sameness_overtime.R` : Figure 3 Panels A and B
8. `5d_sameness_macrointeract.do` + `5d_figure3_macro_micro.R` : Figure 3, Panels C and D
9. `6a_robustness_crossection.do` : Table A2
10. `6b_robustness_longitudinal.do` : Table A3
11. `6c_nonlinearity_sameness.do` + `6c_figure_s5_nonlinearity.R` : Figure S5 in Appendix.

# Required Packages in Stata and R

## Stata 
To run the Stata Do file, you need to install the following packages

1. Reporting the marginal change
  + net from http://www.indiana.edu/~jslsoc/stata/
  + net install spost13_ado 

2. Reporting regression table 
  + ssc install estout, replace 

3. Estimating fixed effects models
  + ssc install reghdfe, replace

## R 
All the following packages should be installed in advance.

```
list_packages = c('rio', 'fst', 'data.table', 'bit64', 
  'refinr', 'diagis', 'stringr', 
  'ggplot2', 'gridExtra', 'ggsci','zoo','tidyverse',
  'wordcloud','tm','lmtest')
install.packages(list_packages))
```

